﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RkLibs.Configuration;
namespace CustomErp.Model
{
    public class DbFeild
    {
        public string DbName { get; set; }
        public string DisName { get; set; }
        public FieldType Type { get; set; }
        public bool IsKeyFeild { get; set; }
    }


    public class ItemInformation
    {
        public static int KeyField;
        public static FieldType[] FieldsType { get; set; }
        public static string[] FieldsDisName { get; set; }
        public static string[] FieldsName { get; set; }

        private const string CFG = "DB_FIELD";
        private const string CFG_NAME = "NAME";
        private const string CFG_DIS_NAME = "DISNAME";
        private const string CFG_TYPE = "TYPE";
        private const string CFG_KEY_FIELD = "KEY_FEILD";
        private const char SPLIT_CHAR = ',';

        public static void LoadFieldInfo()
        {
            string str = Cfg.ReadString(CFG,CFG_NAME);
            if (str == "")
            {
                gValue.IsDbReady = false;
                return;
            }
            FieldsName = str.Split(SPLIT_CHAR);
            str = Cfg.ReadString(CFG, CFG_DIS_NAME);
            FieldsDisName = str.Split(SPLIT_CHAR);
            str = Cfg.ReadString(CFG, CFG_TYPE);
            string[] ArrStr = str.Split(SPLIT_CHAR);
            FieldsType = new FieldType[ArrStr.Length];
            for (int idx = 0; idx < ArrStr.Length; idx++)
            {
                FieldsType[idx] = (FieldType)Convert.ToInt32(ArrStr[idx]);
            }
            KeyField = Cfg.ReadInt(CFG, CFG_KEY_FIELD);
        }
        public static void SaveFieldInfo()
        {
            string str = "";
            if (null != FieldsName)
            {
                str = String.Join(SPLIT_CHAR.ToString(), FieldsName);
                Cfg.WriteConfig(CFG, CFG_NAME, str);
            }
            if (null != FieldsDisName)
            {
                str = String.Join(SPLIT_CHAR.ToString(), FieldsDisName);
                Cfg.WriteConfig(CFG, CFG_DIS_NAME, str);
            }
            if (null != FieldsType)
            {
                str = String.Join(SPLIT_CHAR.ToString(), FieldsType);
                Cfg.WriteConfig(CFG, CFG_TYPE, str);
            }
        }

        
        public object KeyFieldValue;

        
        
        public static object[] FieldsValue { get; protected set; }


        public ItemInformation()
        {

        }


        public bool Update()
        {
            return true;
        }
    }
}
